﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MySoftWare.SimpleMVC.Controllers
{
    /// <summary>
    /// added by lqm 2013.06.19  处理ajax请求后异常返回，通过json反馈
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
    public class MyHandleErrorAttribute : FilterAttribute, IExceptionFilter
    {
        public void OnException(ExceptionContext filterContext)
        {
            //when ajax error happen
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.ExceptionHandled = true;
                filterContext.Result = new JsonResult
                {
                    Data = new
                    {
                        Success = false,
                        Message = filterContext.Exception.Message

                    },
                };
            }

        }
    }

    /// <summary>
    /// 公共的控制器基类 added by lqm 2013.05.30
    /// </summary>
    public class BaseController : Controller
    {

    }
}
